package com.qfedu.yuxiaoer.common.service.impl;

import com.qfedu.yuxiaoer.common.service.PresetService;
import com.qfedu.yuxiaoer.dto.House;
import com.qfedu.yuxiaoer.entity.HouseDetachedBuild;
import com.qfedu.yuxiaoer.entity.HouseLease;
import com.qfedu.yuxiaoer.entity.PreLease;
import com.qfedu.yuxiaoer.entity.Source;
import com.qfedu.yuxiaoer.mapper.HouseDetachedBuildMapper;
import com.qfedu.yuxiaoer.mapper.HouseLeaseMapper;
import com.qfedu.yuxiaoer.mapper.PreLeaseMapper;
import com.qfedu.yuxiaoer.mapper.SourceMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 查询预订接口实现类
 */
@Service
public class PresetServiceImpl implements PresetService {
    @Autowired
    private HouseLeaseMapper houseLeaseMapper;
    @Autowired
    private HouseDetachedBuildMapper houseDetachedBuildMapper;
    @Autowired
    private PreLeaseMapper preLeaseMapper;
    @Override
    public List<PreLease> selectPreset(String city, String type, PreLease preLease) {
        //合租整租查询
        if(type=="合租" || type=="整租"){
            List<PreLease> list = preLeaseMapper.selectPre(city,type,preLease);
            return list;
            //独栋查询
        } else if (type=="独栋") {
            List<PreLease> list = preLeaseMapper.selectPre1(city,type,preLease);
            return list;
        }
        //全查
        List<PreLease> list = new ArrayList<>(preLeaseMapper.selectPre(city,type,preLease));

        list.addAll(preLeaseMapper.selectPre1(city,type,preLease));

        return list;
    }

    /**
     * 模糊查询 两个表 合并
     * @param string
     * @return
     */
    @Override
    public List<House> selectHouse(String string) {
        //查询house_lease表
        List<House> list = new ArrayList<>(houseLeaseMapper.selectHouse(string));
        //查询house_detached_build 跟house_lease表查询数据合并
        list.addAll(houseDetachedBuildMapper.selectBuild(string));
        return list;
    }
}
